import java.util.Random;

/**
 * 加减法口算练习系统-v0.2
 * 改进功能：答案验证、结果范围限制、格式化输出
 */
public class CalculationSystemV02 {
    public static void main(String[] args) {
        Random random = new Random();
        int totalQuestions = 50;
        int problemsPerLine = 5; // 每行显示的算式数量
        
        System.out.println("加减法口算练习系统-v0.2");
        System.out.println("========================");
        
        for (int i = 1; i <= totalQuestions; i++) {
            int num1, num2, result;
            String operator;
            
            // 随机决定加法或减法
            boolean isAddition = random.nextBoolean();
            
            if (isAddition) {
                // 生成加法算式：确保和不超过100
                num1 = random.nextInt(99) + 1; // 1-99
                num2 = random.nextInt(100 - num1) + 1; // 1到(100-num1)
                result = num1 + num2;
                operator = "+";
            } else {
                // 生成减法算式：确保差不小于0
                num1 = random.nextInt(100) + 1; // 1-100
                num2 = random.nextInt(num1) + 1; // 1到num1
                result = num1 - num2;
                operator = "-";
            }
            
            // 构建算式字符串（包含答案）
            String expression = String.format("%2d %s %2d = %-3d", 
                num1, operator, num2, result);
            
            // 输出算式，每行多个
            System.out.print(" " + expression);
            
            // 每行结束时换行
            if (i % problemsPerLine == 0) {
                System.out.println();
            }
        }
        
        if (totalQuestions % problemsPerLine != 0) {
            System.out.println(); // 最后一行补换行
        }
    }
}